<script setup lang="ts">
import pageFooter from "@/components/pageFooter/index.vue";
import { onLoad, onReady, onShow } from "@dcloudio/uni-app";
import { getSave } from "@/api/user";
import { getNoAuthInfo } from "@/api/user";
import { useTheme } from "@/composables/useTheme";
import Cache from "@/utils/cache";
import wx from "weixin-js-sdk";
const { colorStyle } = useTheme();
let shareData = ref({
  business_id: "",
  urltype: "",
});
let isShowAllMenu = ref(false);
let business_id = ref("");
onLoad((option) => {
  uni.showLoading();
  if (option.business_id) {
    business_id.value = option.business_id;
    shareData.value.business_id = option.business_id;
    shareData.value.urltype = option.urltype;
    Cache.set("urltype", option.urltype);
    Cache.set("business_id", option.business_id);
    isShowAllMenu.value = false;
  }
});
onShow(() => {
  getNoAuthInfoHandler();
  setShareHandler();
  if (Cache.get("business_id")) {
    isShowAllMenu.value = false;
  } else {
    isShowAllMenu.value = true;
  }
});
let userInfo = ref({});
let enterprise_address = ref("");
let contacts = ref([]);
function getNoAuthInfoHandler() {
  let params = { business_id: business_id.value };
  getNoAuthInfo(params).then((res: any) => {
    uni.hideLoading();
    const data = res.data.info;
    userInfo.value = data;
    enterprise_address.value = data.enterprise_address;
    contacts.value = data.contacts;
  });
}
function setShareHandler() {
  wx.ready(() => {
    wx.showAllNonBaseMenuItem();
    wx.hideMenuItems({
      menuList: ["menuItem:copyUrl"], // 屏蔽复制链接
    });
  });
}
function makePhone(phone) {
  uni.makePhoneCall({
    phoneNumber: phone, //仅为示例
    fail: (err) => {
      console.log(err, "----");
    },
  });
}
function copyUrlHandler() {
  uni.setClipboardData({
    data: enterprise_address.value,
    success: function () {
      uni.showToast({
        title: "复制成功",
        icon: "success",
        duration: 2000,
      });
    },
  });
}
</script>
<template>
  <view class="wrap" :style="colorStyle">
    <view class="top_box flex_fc">
      <!-- <view class="logo">
        <image :src="userInfo.logo" mode="scaleToFill" v-if="userInfo.logo" />
        <image src="@/static/image/logo.png" mode="scaleToFill" v-else />
      </view> -->
      <view class="title">
        <text v-if="userInfo.enterprise_name">{{
          userInfo.enterprise_name
        }}</text>
        <text v-else>暂无名称</text>
      </view>
    </view>
    <view class="container">
      <view class="header"> 黄金 铂金 销售和回购 </view>
      <view class="body">
        <view class="card_box">
          <view class="card_title">
            营业范围/ <text class="sub_title">Business Scope</text>
          </view>
        </view>
        <view class="text_box">
          {{ userInfo.nature_of_business||'暂无营业范围' }}
        </view>
        <view class="card_box">
          <view class="card_title">
            联系我们/ <text class="sub_title">Contact Us</text>
          </view>
          <view class="text_box">
            <template v-if="contacts.length">
              <view
                class="text_item flex_sb"
                v-for="(item, index) in contacts"
                :key="index"
                @click="makePhone(item.phone)"
              >
                <view class="left">
                  <text class="iconfont icon-dianhua"></text>
                  <text>{{ item.name }} {{ item.phone }}</text>
                </view>
                <view class="right_btn">拨打</view>
              </view>
            </template>

            <view class="text_item address_box flex_sbs" v-if="enterprise_address">
              <view>
                <text class="iconfont icon-dizhi"></text>
                <text>{{ enterprise_address }}</text>
              </view>
              <view class="right_btn" @click="copyUrlHandler">复制</view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view class="uni-p-b-98"></view>
    <pageFooter
      :isShowAllMenu="isShowAllMenu"
      :shareData="shareData"
      :selected="4"
    ></pageFooter>
  </view>
</template>

<style scoped lang="scss">
.wrap {
  padding-top: 50rpx;
  min-height: 100vh;
  background-image: radial-gradient(
    at top,
    rgba(207, 214, 217, 1),
    rgba(234, 232, 221, 1) 10%,
    rgba(250, 249, 244, 1) 50%,
    rgba(214, 221, 222, 1) 100%
  );
  .container {
    width: 622rpx;
    margin: 0 auto;
    .header {
      box-shadow: 0px 0px 20rpx 0px rgba(189, 197, 200, 0.2);
      background: rgba(216, 222, 225, 1);
      height: 88rpx;
      line-height: 88rpx;
      color: rgba(255, 255, 255, 1);
      text-align: center;
      font-size: 30rpx;
      font-weight: 600;
    }
    .body {
      background: #fff;
      padding: 25rpx 30rpx;
      .card_box {
        padding: 15rpx 20rpx;
        border: 2px solid rgba(216, 222, 225, 1);
        margin-bottom: 20rpx;
        .card_title {
          font-weight: 600;
          color: rgba(75, 76, 76, 1);
          .sub_title {
            color: #999;
            font-size: 32rpx;
          }
        }
      }
      .text_box {
        margin-top: 20rpx;
        color: rgba(75, 76, 76, 1);
        font-size: 28rpx;
        line-height: 50rpx;
        margin-bottom: 20rpx;
        .address_box{
          line-height: 40rpx !important;
        }
        .text_item {
          line-height: 55rpx;
          .iconfont {
            color: rgba(75, 76, 76, 1);
            font-size: 30rpx;
            margin-right: 10rpx;
          }
          .right_btn {
            flex-shrink: 0;
            width: fit-content;
            line-height: 1;
            font-size: 26rpx;
            color: rgba(75, 76, 76, 1);
            background: #ddcb9d;
            border-radius: 10rpx;
            padding: 10rpx 20rpx;
          }
        }
      }
    }
  }
  .top_box {
    width: 100%;
    margin-bottom: 30rpx;
    .logo {
      width: 150rpx;
      height: 150rpx;
      margin-bottom: 30rpx;
      image {
        width: 100%;
        height: 100%;
      }
    }
    .title {
      font-size: 64rpx;
      font-weight: 600;
      color: rgba(39, 38, 54, 1);
      margin-bottom: 16rpx;
    }
    .edit_box {
      color: rgba(63, 64, 66, 1);
      font-size: 24rpx;
      border-radius: 999rpx;
      background: rgba(255, 255, 255, 1);
      .iconfont {
        font-size: 24rpx;
        color: rgba(63, 64, 66, 1);
      }
    }
  }
}
</style>
